package main;

import java.awt.Color;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JTextArea;

/**
 * Small class that helps with logging of messages from the server
 * @author Mark van der Wal
 */
public class Logger 
{
    private static JTextArea mLogArea;
    
    /**
     * 
     * @param logArea 
     */
    public static void SetLogger(JTextArea logArea)
    {
        mLogArea = logArea;
        mLogArea.setFont(new Font("Consolas", Font.BOLD, 12));
        mLogArea.setBackground(Color.BLACK);
        mLogArea.setForeground(Color.ORANGE);
    }
    
    /**
     * 
     * @param log 
     */
    public static synchronized void AddLog(String log)
    {
        String time = CurrentTime();
        mLogArea.append("[" + time + "] " + log + "\n");
        mLogArea.setCaretPosition(mLogArea.getCaretPosition());
    }

    /**
     * 
     * @return The current time in string format hours:minutes:seconds
     */
    private static String CurrentTime()
    {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        Calendar c1 = Calendar.getInstance(); // today
        
        return sdf.format(c1.getTime());
    }
    
    /**
     * Returns the currentDate
     * @return 
     */
    public static String CurrentDate()
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        Calendar c1 = Calendar.getInstance(); // today
        
        return sdf.format(c1.getTime());
    }
}
